package cn.ac.cintcm.webapp.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import cn.ac.cintcm.model.FeedBack;
import cn.ac.cintcm.service.FeedbackManager;

public class FeedBackController extends MultiActionController {
	
    private transient final Log log = LogFactory.getLog(FeedBackController.class);
	private FeedbackManager fm;
	public void setFeedBackManager(FeedbackManager gm) {
		this.fm = gm;
	}

	public ModelAndView feedbacks(HttpServletRequest request, HttpServletResponse response) throws Exception {
		log.debug("entering feedbacks");
		String username = request.getRemoteUser();
		List<FeedBack> list =  fm.getAll(username);
		ModelAndView mv = new ModelAndView("feedbacks").addObject("feedBackList",list);;
		return mv;
	}
	
	public ModelAndView feedbacknew(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String username = request.getRemoteUser();
		log.debug("entering feedbacknew, userId:" + username);
		List<FeedBack> feedbacks = fm.getUnread(username);
		//gm.clearUnread(userId);
		ModelAndView mv = new ModelAndView("feedbacks").addObject("feedBackList", feedbacks);
		return mv;
	}
}
